package com.semlab.client.widgets;

import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.FontWeight;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.*;
import com.semlab.client.bundle.Resources;

public class LoadingIndicator extends Container<HorizontalPanel> {

    private Image loading = new Image(Resources.INSTANCE.smallLoading());
    private SimplePanel imageContainer;
    private Label label;

    public LoadingIndicator() {
        super(new HorizontalPanel());
        label = new Label("");
        imageContainer = new SimplePanel();
        addWidget(imageContainer);
        WidgetUtils.glue(getTopContainer(), "10px");
        addWidget(label);
        label.getElement().getStyle().setColor("#3A3A3A");
        getTopContainer().setCellVerticalAlignment(label, HasVerticalAlignment.ALIGN_MIDDLE);
        getTopContainer().setCellHorizontalAlignment(label, HasHorizontalAlignment.ALIGN_CENTER);
        getTopContainer().getElement().getStyle().setProperty("margin", "5px 0px");
        hide();
        loading.getElement().getStyle().setMarginTop(5, Style.Unit.PX);
    }

    public void showLoading(String message) {
//        setVisible(false);
        loading.setVisible(true);
        label.setVisible(true);
        imageContainer.setWidget(this.loading);
        label.setText(message);
        label.getElement().getStyle().setFontWeight(FontWeight.BOLD);
//        getTopContainer().setVisible(true);
    }

    public void hide() {
//        setVisible(false);
        loading.setVisible(false);
        label.setVisible(false);
    }


}
